﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RangePad : MonoBehaviour
{

    public GameObject objToInst;
    public bool isbag;
    GameObject obj;
    bool canDestroy = true;

    private void OnMouseDown()
    {
        obj = Instantiate(objToInst) as GameObject;
        obj.transform.position = transform.position;
    }

    LayerMask mask = 1 << 8;
    Ray clickRay;
    RaycastHit clickPoint;
    private void OnMouseDrag()
    {
        clickRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(clickRay, out clickPoint, mask))
        {
            obj.transform.position = new Vector3(clickPoint.point.x, transform.position.y, clickPoint.point.z);
        }
    }

    private void OnMouseUp()
    {
        if (obj.transform.position.x > -2f && obj.transform.position.x < 0.5f
            && obj.transform.position.z > -5.7f && obj.transform.position.z < -3.4f && GameController.instance.hasBox == true)
        {
            if (isbag)
            {
                GameController.instance.currentBox.transform.Find("plastic_big_01").gameObject.SetActive(true);
                GameController.instance.isBoxBag = true;
            }
            else
            {
                GameController.instance.currentBox.transform.Find("foam_big_01").gameObject.SetActive(true);
                GameController.instance.isBoxPlatform = true;
            }
        }
        Destroy(obj);
    }
}